package com.adinnet.admin.word.service.impl;

import com.adinnet.admin.word.model.Word;
import com.adinnet.admin.word.mapper.WordMapper;
import com.adinnet.admin.word.service.WordService;
import com.adinnet.core.JsonResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 重点词汇表 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Service
public class WordServiceImpl extends ServiceImpl<WordMapper, Word> implements WordService {


    @Autowired
    private WordMapper wordMapper;
    /**
     * @Description: 重点词汇列表
     * @author zYshuai
     * @Date: 2020/12/15 9:51
    * @param keyword:
    * @return: java.util.List<com.adinnet.admin.word.model.Word>
     */
    @Override
    public List<Word> wordList(String keyword) {
        return wordMapper.selectList(new QueryWrapper<Word>().eq("deleted", 0).eq(StringUtils.isNotBlank(keyword), "word_name", keyword).orderByDesc("created_date"));
    }

    /**
     * @Description: 删除重点词汇
     * @author zYshuai
     * @Date: 2020/12/15 9:51
    * @param wordId:
    * @return: com.adinnet.core.JsonResult
     */
    @Override
    public JsonResult delete(Integer wordId) {
        Word word = new Word();
        word.setDeleted(true);
        wordMapper.update(word, new QueryWrapper<Word>().eq("id", wordId));
        return JsonResult.ok("删除成功");
    }
}
